package com.itheima.thread.线程创建.demo3;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
// 1.implements Callable 开发流程
public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //线程开启后要执行里面的call方法
        MyCallable mc = new MyCallable();
        //可以获得线程执行完毕的结果,也可以作为参数传递给线程对象
        //3.完整的多线程实现
        //        多个线程不能共享同一个Task
        FutureTask<String> ft1 = new FutureTask<>(mc);
        FutureTask<String> ft2 = new FutureTask<>(mc);
        //创建线程对象
        Thread t1 = new Thread(ft1);
        t1.setName("张三");
        t1.start();
        Thread t2 = new Thread(ft2);
        t2.setName("李   四");
        t2.start();
        //2 get方法的阻塞问题
        //        get方法只有线程执行完,返回对应的结果数据,当前方法才会向下继续执行
        String s1 = ft1.get();
        String s2 = ft2.get();
        System.out.println("s1 = " + s1);
        System.out.println("s2 = " + s2);
    }
}
